package com.xdcplus.web.service.trace.impl;

import com.xdcplus.mp.service.impl.BaseServiceImpl;
import com.xdcplus.web.common.pojo.entity.trace.TracePacketBatchInfo;
import com.xdcplus.web.common.pojo.vo.trace.PacketPrdInfoVO;
import com.xdcplus.web.common.pojo.vo.trace.PacketShortInfoVO;
import com.xdcplus.web.common.pojo.vo.trace.PacketTraceInfoVO;
import com.xdcplus.web.common.pojo.vo.trace.TracePacketBatchInfoVO;
import com.xdcplus.web.mapper.trace.PacketTraceWashMapper;
import com.xdcplus.web.service.trace.PacketTraceWashService;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;


@Service
public class PacketTraceWashServiceImpl
        extends BaseServiceImpl<PacketTraceWashMapper,TracePacketBatchInfo,TracePacketBatchInfo, TracePacketBatchInfoVO>
            implements PacketTraceWashService {


    @Override
    public Long getLastPacketId() {
        return baseMapper.getLastPacketId();
    }

    @Override
    public List<PacketShortInfoVO> getPacketInfo(Long lastId, boolean isReversed) {
        if (isReversed) {
            return baseMapper.getPacketInfoReversed(lastId);
        }else {
            return baseMapper.getPacketInfo(lastId);
        }
    }

    @Override
    public List<PacketPrdInfoVO> getPrdByCodes(List<String> packetCodes) {
        return null;
    }

    @Override
    public List<PacketTraceInfoVO> getTraceInfoByPacketCodes(List<String> packetCodes, Timestamp minTime, Timestamp maxTime) {
        return baseMapper.getTraceInfoByPacketCodes(packetCodes,minTime,maxTime);
    }

    @Override
    public List<PacketTraceInfoVO> getTraceInfoByToolCodes(List<String> toolCodes, Timestamp minTime, Timestamp maxTime) {
        return baseMapper.getTraceInfoByToolCodes(toolCodes,minTime,maxTime);
    }

    @Override
    public PacketTraceInfoVO getTraceInfoByCreatedTime(String endTime, Timestamp minTime, Timestamp maxTime,
                                                       Integer unpackTimeRange) {
        String startTime = LocalDateTime.parse(endTime,
                DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
        ).minusHours(unpackTimeRange).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        return baseMapper.getTraceInfoByCreatedTime(startTime, endTime,minTime,maxTime);
    }

    @Override
    public PacketTraceInfoVO getMeterialOrderByCreatedTime(String endTime, Timestamp minTime, Timestamp maxTime, Integer batchMtrlTimeRange) {
        String startTime = LocalDateTime.parse(endTime,
                DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
            ).minusHours(batchMtrlTimeRange).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        return baseMapper.getMeterialOrderByCreatedTime(startTime,endTime,minTime,maxTime);
    }


}
